<?
/*
 * Using streams with the proper filters to read a file handle would be the
 * best solution for this problem, but there is a good amount of learning
 * overhead to do it.  Thus I am going with the simpler solution which might
 * have poor performance in comparison.
 */

class Dictionary {

    private $words = array();

    function __construct($dict_file)
    {
        while (!feof($dict_file)) {
            $this->words[strtolower(rtrim(fgets($dict_file)))] = true;
        }
    }

    function check($word)
    {
        $lowercased_word = strtolower($word);

        if (array_key_exists($lowercased_word, $this->words)) {
            return true;
        }
        else {
            return false;
        }
    }
}


$dict_file = fopen($argv[1], 'r');
$dictionary = new Dictionary($dict_file);
// explode() leaves in empty strings when there are multiple spaces in a row.
$possible_word_array = explode(" ", $argv[2]);
$word_array = array();
foreach ($possible_word_array as $word) {
    if (strlen($word) != 0) {
        $word_array[] = $word;
    }
}

foreach ($word_array as $word) {
    if (!$dictionary->check($word)) {
        print "$word\n";
    }
}
?>
